package interpreter.bytecodes.debuggerByteCodes;

import interpreter.VirtualMachine;
import interpreter.bytecodes.ByteCode;
import interpreter.debugger.DebugVirtualMachine;
import java.util.Vector;

/**
 *
 * @author Kris Selbekk
 */
public class FunctionByteCode extends ByteCode {
    private String funcName;
    private int startLine, endLine;

    public void exec( VirtualMachine rt ) {
        DebugVirtualMachine vm = (DebugVirtualMachine) rt;

        // Registers function
        vm.setFunctionName( funcName );
        vm.setStartLine(startLine);
        vm.setEndLine(endLine);

        // Checks for step-in fail
        if( vm.formalCount() == vm.argCount() )
            vm.isStepIn(false);
    }
    public void init( Vector<String> args ) {
        try {
            funcName = args.get(0);
            if( args.size() == 3 ) {
                startLine = Integer.parseInt(args.get(1));
                endLine = Integer.parseInt(args.get(2));
            }
        } catch( NumberFormatException nfe ) {
            // If bad format
            System.out.println("Bad format!");
            System.exit(-1);
        } catch( NullPointerException npe ) {
            // If argument missing
            System.out.println("Argument given = null.");
            System.exit(-1);
        }
    }
    public Object getArgs() {
        return funcName + " " + startLine + " " + endLine;
    }
}
